<template>
	<view class="page">
		<view class="page_title justify-content-sp">
			<view class="page_title_cont" :class="indexList_index == item.id?'selected':''"
				v-for="(item,index) in indexList" :key="index" @click="changeIndex(item.id)">
				{{item.text}}
			</view>
		</view>
		<view class="input justify-content-sp">
			<input type="text" placeholder="请输入手机号或者昵称" v-model="text" />
			<uni-icons type="search" size="20" @click="search"></uni-icons>
		</view>
		<checkbox-group @change="checkboxChange">
			<view class="body " v-for="(item,index) in dataList" :key="item.index">
				<view class="justify-content-start">
					<view class="check">
						<label v-if="indexList_index == 0">
							<checkbox :value="item.value" :checked="item.checked" class="circle" />
						</label>
					</view>
					<view class="" style="flex: 1;">
						<view class="body_cont justify-content-start body_fir">
							<view class="body_cont_left">
								<view class="image">
									<image :src="item.avatar" mode="" class="img"></image>
								</view>
								<!-- 	<label>
									<checkbox :value="item.id" :checked="item.checked" class="circle" />
								</label> -->
							</view>
							<view class="body_cont_right justify-content-start">
								<view class="">
									商家昵称:{{item.shop_name}}
								</view>
								<view class="copy_image" @click="copy(item.name)">
									<image src="../../static/index/copy.png" mode="" class="img"></image>
								</view>
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								姓名 ：
							</view>
							<view class="body_cont_right justify-content-start">
								<view class="">
									{{item.name}}
								</view>
								<view class="copy_image" @click="copy(item.rates)">
									<image src="../../static/index/copy.png" mode="" class="img"></image>
								</view>
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								提现方式 ：
							</view>
							<view class="body_cont_right">
								{{item.type==2?'支付宝':item.type==1?'微信':'银行卡'}}
							</view>
						</view>
						<view class="body_cont justify-content-start" v-if="item.type==3">
							<view class="body_cont_left">
								账户类型 ：
							</view>
							<view class="body_cont_right">
								{{item.bank_type}}
							</view>
						</view>
						<view class="body_cont justify-content-start" v-if="item.type==3">
							<view class="body_cont_left">
								所属银行 ：
							</view>
							<view class="body_cont_right">
								{{item.bank_from}}
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								{{item.type==3?'银行账号':'支付宝账号'}} ：
							</view>
							<view class="body_cont_right justify-content-start">
								<view class="">
									{{item.account}}
								</view>
								<view class="copy_image" @click="copy(item.account)">
									<image src="../../static/index/copy.png" mode="" class="img"></image>
								</view>
							</view>
						</view>
						<!-- <view class="body_cont justify-content-start">
							<view class="body_cont_left">
								商家数量 ：
							</view>
							<view class="body_cont_right">
								{{item.number}}
							</view>
						</view> -->
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								申请时间 ：
							</view>
							<view class="body_cont_right">
								{{item.create_date}}
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								提现状态 ：
							</view>
							<view class="body_cont_right">
								{{item.status=="rejected"?'拒绝':'同意'}}
							</view>
						</view>
						<view class="body_cont justify-content-start">
							<view class="body_cont_left">
								到账时间 ：
							</view>
							<view class="body_cont_right">
								{{item.arrival_time}}
							</view>
						</view>
						<view class="body_cont_se justify-content-sp" @click="toPath(2)">
							<view class="body_cont_se_left">
								<view class="body_cont_se_left_thr">
									提现金额
								</view>
								<view class="body_cont_se_left_four">
									￥{{item.now_money}}
								</view>
							</view>
							<view class="body_cont_se_right">
								<view class="body_cont_se_right_thr">
									到账金额
								</view>
								<view class="body_cont_se_right_four">
									￥{{item.money}}
								</view>
							</view>
						</view>
					</view>
				</view>
				<view class="body_cont_thr justify-content-sp" v-if="indexList_index == 0">
					<view class="btn_cs_left" @click="openRefuse(item.id)">
						拒绝审批
					</view>
					<view class="btn_cs_right" @click="open(item.id)">
						通过审批
					</view>
				</view>
				<!-- 	<view class="" v-else>
					
				</view> -->
			</view>
		</checkbox-group>
		<uni-popup ref="status" type="center" border-radius="10px 10px 0 0">
			<view class="status_popup">
				<view class="status_popup_title">
					请选择原因
				</view>
				<view class="status_popup_cont">
					<uni-data-select v-model="type_index" :localdata="range" @change="change"></uni-data-select>
				</view>
				<view class="btn btn_css" @click="next">
					确定
				</view>
			</view>
		</uni-popup>
		<view style="height: 50px; background-color: #f5f5f5;">
		</view>
		<view class="btn_cs justify-content-sp" v-if="indexList_index == 0">
			<view class="">
				<checkbox-group @change="choose_isAll">
					<label>
						<checkbox value="isAll" :checked="isAll" style="transform:scale(0.7)" />全选
					</label>
				</checkbox-group>
			</view>
			<view class="btn_cs_right justify-content-start">
				<view class="btn_css" @click="openRefuse">
					批量拒绝
				</view>
				<view class="btn_css blue" @click="open">
					批量通过
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getApproval,
		checkApproval
	} from '../../api/index/index.js'
	export default {
		data() {
			return {
				indexList: [{
						id: 0,
						text: "待审批"
					},
					{
						id: 1,
						text: "已审批"
					}
				],
				indexList_index: 0,
				type_index: '',
				range: [{
						value: 1,
						text: "限制收款"
					},
					{
						value: 2,
						text: "冻结账号"
					}
				],
				text: '',
				dataList: [],
				isAll: false,
				status_: 0,
				change_type_index: '',
				rejected: "rejected", //拒绝
				successed: "successed", //通过
				re_id: '',
				index_list: []
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			init() {
				var data = {
					check: this.indexList_index
				};
				getApproval(data).then(res => {
					for (var i = 0; i < res.data.length; i++) {
						res.data[i].checked = false;
					};
					this.dataList.push(...res.data)
				})
			},
			change_type(e) {
				this.change_type_index = e;
			},
			change(e) {
				console.log(e);
			},
			next() {
				let newArr = this.index_list.join(',');
				console.log(newArr);
				var data = {
					id: newArr,
					status: this.rejected
				}
				checkApproval(data).then(res => {
					uni.showToast({
						"icon": "success",
						"title": res.msg
					})
				})
				this.$refs.status.close('center');
				this.indexList_index = 0;
				this.dataList = [];
				this.init();
			},
			open(e) {
				var data = {
					id: e,
					status: this.successed
				}
				checkApproval(data).then(res => {
					uni.showToast({
						"icon": "success",
						"title": res.msg
					})
				})
			},
			// 拒绝审批
			openRefuse(e) {
				this.index_list.push(e);
				this.$refs.status.open('center')
			},
			choose_isAll(e) {
				console.log(e.detail.value);
				if (e.detail.value[0] == "isAll") {
					for (var i = 0; i < this.dataList.length; i++) {
						this.dataList[i].checked = true;
						this.index_list.push(this.dataList[i].id);
					}
					console.log(111, this.index_list);
				} else {
					for (var i = 0; i < this.dataList.length; i++) {
						this.dataList[i].checked = false
					}
					this.index_list = []
				}
			},
			checkboxChange: function(e) {
				var values = e.detail.value;
				this.index_list = e.detail.value;
				for (var i = 0, lenI = this.dataList.length; i < lenI; ++i) {
					const item = this.dataList[i]
					if (values.includes(item.value)) {
						this.$set(item, 'checked', true)
					} else {
						this.$set(item, 'checked', false)
					}
				}
			},
			//选择顶部下标
			changeIndex(e) {
				this.indexList_index = e;
				this.dataList = [];
				this.init();
			},
			// 搜索
			search() {
				console.log("搜索", this.text);
			},
			// 复制
			copy(e) {
				uni.setClipboardData({
					data: e,
					success: function() {
						console.log('复制成功');
					},
					fail: function(err) {
						console.log('复制失败');
					}
				});
			},
			toPath(e) {
				if (e == 1) {
					uni.navigateTo({
						url: '/pages/business/addBusiness'
					})
				} else if (e == 2) {
					uni.navigateTo({
						url: '/pages/daily/index'
					})
				}
			},
			topathUrl(e) {
				uni.navigateTo({
					url: `/pages/merchantListings/addMerchantListings?id=` + e.id
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		min-height: 100%;

		.page_title {
			margin: 30rpx;
			padding: 20rpx 30rpx;

			.page_title_cont {
				padding-bottom: 10rpx;
				border-bottom: 2 px solid #b2b2b2;
			}

			.selected {
				border-bottom: 2px solid #6796ff;
			}
		}

		.input {
			margin: 30rpx;
			padding: 20rpx 40rpx;
			border-radius: 50rpx;
			background-color: white;
		}

		.body {
			.check {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
			}

			.text {
				position: absolute;
				color: white;
				margin-top: -264px;
				text-align: center;
				width: 630rpx;

				.text_1 {
					line-height: 25px;
				}

				.text_2 {
					line-height: 25px;
				}

				.text_3 {
					font-size: 30px;
				}
			}

			.body_fir {
				border-bottom: 1px solid #b2b2b2;
				padding-bottom: 10rpx;
			}

			.body_cont {
				line-height: 25px;

				.body_cont_left {
					color: black;

					.image {
						height: 24px;
						width: 24px;
						padding: 0 10rpx;

						.img {
							width: 100%;
							height: 100%;
						}
					}
				}

				.body_cont_right {}
			}

			.body_cont_se {
				background-color: #f5f5f5;
				padding: 30rpx 80rpx;
				margin: 30rpx 0;
				border-radius: 15rpx;

				.body_cont_se_left {
					text-align: center;

					.body_cont_se_left_fir {
						font-size: 14px;
					}

					.body_cont_se_left_se {
						font-weight: 600;
					}

					.body_cont_se_left_thr {
						font-size: 14px;
					}

					.body_cont_se_left_four {
						color: #32b26c;
						font-weight: 600;
					}
				}

				.body_cont_se_right {
					text-align: center;


					.body_cont_se_right_se {
						color: red;
						font-weight: 600;
					}


					.body_cont_se_right_four {
						color: red;
						font-weight: 600;
					}
				}
			}

			.body_cont_se2 {
				background-color: #626262;
				padding: 30rpx 80rpx;
				margin: 30rpx 0;
				border-radius: 15rpx;

				.body_cont_se_left {
					text-align: center;

					.body_cont_se_left_fir {
						font-size: 14px;
					}

					.body_cont_se_left_se {
						font-weight: 600;
					}

					.body_cont_se_left_thr {
						margin-top: 10rpx;
						font-size: 14px;
					}

					.body_cont_se_left_four {
						color: #164631;
						font-weight: 600;
					}
				}

				.body_cont_se_right {
					text-align: center;

					.body_cont_se_right_fir {
						font-size: 14px;
					}

					.body_cont_se_right_se {
						color: #5e0e0a;
						font-weight: 600;
					}

					.body_cont_se_right_thr {
						margin-top: 10rpx;
						font-size: 14px;
					}

					.body_cont_se_right_four {
						font-weight: 600;
					}
				}
			}

			.body_cont_thr {
				padding: 0 30rpx;

				.btn_cs_left {
					padding: 20rpx 70rpx;
					border: 1px solid #b2b2b2;
					border-radius: 50rpx;
					background-color: white;
				}

				.btn_cs_right {
					padding: 20rpx 70rpx;
					border: 1px solid #6796ff;
					border-radius: 50rpx;
					background-color: #6796ff;
					color: white;
				}
			}
		}

		.btn_cs {
			position: fixed;
			bottom: 0;
			width: 100%;
			background-color: white;
			padding: 30rpx;

			.btn_cs_right {
				padding: 0 30rpx;

				.btn_css {
					border: 1px solid #b2b2b2;
					border-radius: 30rpx;
					margin: 0 30rpx;
					padding: 0 10px;
				}

				.blue {
					background-color: #4b82ff;
					color: white;
					border: 1px solid #4b82ff;
				}
			}
		}

		.status_popup {
			background-color: white;
			width: 500rpx;
			padding: 30rpx;
			border-radius: 30rpx;

			.status_popup_title {
				font-weight: 550;
				padding: 30rpx;
				text-align: center;
			}

			.status_popup_cont {
				padding: 0 30rpx;
			}

			.btn_css {
				margin: 30rpx 0 0 0;
			}
		}
	}
</style>